<?php
class MSetting extends CI_Model{

	public function __construct()
    {
        parent::__construct();
    }

    function getLanguages()
    {
         $data = array();
	     $this->db->order_by("name");
	     $Q = $this->db->get('language');
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	    }
	    $Q->free_result();  
	    return $data; 
    }
    
    function getLanguageActiveCode($code)
    {
        $output = $this->db->query("SELECT `activate` FROM `language` WHERE `code`='".$code."' LIMIT 0,1")->row()->activate;
        return $output;
    }
    
    function updateLanguageByCode($code)
    {
        $data = array('activate' => db_clean(isset($_POST['activate']) ? 1 : 0));
        $this->db->where('code', db_clean($code));
	    $this->db->update('language',$data);	
    }
	
	function addUser(UserModel $userModel){
        //$this->load->library('usermodel');
        $data = array('Username' => db_clean($userModel->getUserName()),
                    'Password' => db_clean(do_hash($userModel->getPassword()),16),
                    'Email' => db_clean($userModel->getEmail()),
      				'Phone' => db_clean($userModel->getPhone()),
                    'UserTypeID'=>id_clean($userModel->getUserTypeID()),
                    'StaffId'=>id_clean($userModel->getStaffID()),
                    'Activate' => db_clean($userModel->getActivate())
                    );
	   $this->db->set('CreatedDate', 'NOW()', FALSE);
	   $this->db->insert('user',$data);
	}
	
	function updateUser(UserModel $userModel){
	   if($userModel->getPassword() != null || $userModel->getPassword() != '')
       {
	       $data = array('Username' => db_clean($userModel->getUserName()),
                    'Password' => db_clean(do_hash($userModel->getPassword()),16),
                    'Email' => db_clean($userModel->getEmail()),
      				'Phone' => db_clean($userModel->getPhone()),
                    'UserTypeID'=>id_clean($userModel->getUserTypeID()),
                    'Activate' => db_clean($userModel->getActivate())
                    );
	   }
       else{
         $data = array('Username' => db_clean($userModel->getUserName()),
                'Email' => db_clean($userModel->getEmail()),
  				'Phone' => db_clean($userModel->getPhone()),
                'UserTypeID'=>id_clean($userModel->getUserTypeID()),
                'Activate' => db_clean($userModel->getActivate())
                );
       }
       $this->db->set('ModifiedDate', 'NOW()', FALSE);
	   $this->db->where('StaffId',id_clean($userModel->getStaffID()));
	   $this->db->update('user',$data);	
	}
	
	function activateUser($id){
 	 $data = array('activate' => db_clean($_POST['activate']));
 	 $this->db->where('uid', id_clean($id));
	 $this->db->update('user', $data);
	
	}
	
	function inActiveUser($id){
 	 $data = array('activate' => db_clean('0'));
 	 $this->db->where('uid', id_clean($id));
	 $this->db->update('user', $data);
	
	}
}


?>